package com.supergzt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.supergzt.annotation.RequiresLogin;
import com.supergzt.context.SecurityContextHolder;
import com.supergzt.entity.dos.Budget;
import com.supergzt.entity.base.Result;
import com.supergzt.entity.vos.BudgetQueryVo;
import com.supergzt.service.BudgetService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @author 张钧
 * @Description
 * @create 2023-03-29 16:29
 */
@RestController
@RequestMapping("/budget")
public class BudgetController {

	@Resource
	private BudgetService budgetService;

	@GetMapping
	@RequiresLogin
	public Result<?> getBudgetPage(Page<Budget> page){
		return Result.success(budgetService.page(page));
	}

	@GetMapping("query")
	@RequiresLogin
	public Result<?> queryBudget(BudgetQueryVo budgetQueryVo,Page<Budget> page){
		return Result.success(budgetService.queryBudget(budgetQueryVo,page));
	}

	@GetMapping("status")
	@RequiresLogin
	public Result<?> getBudgetStatus(){
		return Result.success(budgetService.getBudgetStatus());
	}

	@PostMapping
	@RequiresLogin
	public Result<?> insertBudget(@RequestBody Budget budget){
		budgetService.save(budget.setUserId(SecurityContextHolder.getUserId()));
		return Result.ok();
	}

	@DeleteMapping
	@RequiresLogin
	public Result<?> deleteBudget(@RequestParam("ids") List<Long> ids){
		budgetService.removeByIds(ids);
		return Result.ok();
	}
}
